<?php

namespace IS\TeamSDK\Utils\Sms;


use IS\TeamSDK\AliyunSmsService;
use IS\TeamSDK\Utils\MTResponse;

class AliSmsService
{
    /**
     * @param $phone
     * @param $product
     * @param $template
     *
     * @return int
     * @throws \Exception
     */
    public function send($phone, $product, $template)
    {
        $keyID = env('ALI_SMS_KEY_ID');
        $keySecret = env('ALI_SMS_KEY_SECRET');

        $number = mt_rand(100000, 999999);
        $templateParam['number'] = $number;

        $dh = AliyunSmsService::getInstance()->setAccessKey($keyID, $keySecret);
        $isSendSuccess = $dh->sendSms($phone, $product, $template, $templateParam);
        if ($isSendSuccess['status'] != '200') MTResponse::jsonToFront('517');

        return $number;
    }
}
